package feeinterface.protocol.reqn;

import com.ulwx.tool.CTime;
import com.ulwx.tool.DateTime;
import com.ulwx.tool.RandomUtils;
import com.ulwx.type.TBoolean;

import feeinterface.protocol.utils.Constants;

public class MonthFeeRequestDate {

	/**
	 * 注册后取得第一次访问日期 2010-12-23
	 */
	public static String getFirstDate() {
		String nextDate = CTime.getCurrentDate();
		DateTime dt = new DateTime();
		int day = dt.getDay();
		if (day < 15) {
			dt.addDays(5);
		} else if (day < 25) {
			dt.addDays(3);
		} else {
		}
		nextDate = CTime.formatDate(dt.getDate(), "yyyy-MM-dd");
		return nextDate;
	}

	/**
	 * 取得当月下次访问日期 2010-12-23
	 */
	public static String getNextDate() {
		String nextDate = CTime.getCurrentDate();
		DateTime dt = new DateTime();
		int day = dt.getDay();
		if (day >= 25) {
			dt.addDays(2);
		} else if (day >= 20) {
			dt.addDays(3);
		} else if (day >= 10) {
			dt.addDays(5);
		} else {
			dt.addDays(10);
		}
		nextDate = CTime.formatDate(dt.getDate(), "yyyy-MM-dd");
		return nextDate;
	}

	/**
	 * 取得下月访问日期 2010-12-23
	 */
	public static String getNextMonthDate() {
		// 2010-12-28进行了优化
		String nextDate = CTime.getCurrentDate();
		DateTime dt = new DateTime();
		int day = dt.getDay();
		//int randNum = (int) (Math.random() * 1000);
		int randDay = 0;
		if (day >= 25) {
			// 得到下月5-25号的日期
			//randDay = randNum % 20 + 5;
			randDay =RandomUtils.nextInt(21)+5;
		} else {
			// 得到下月1-25号的日期
			//randDay = randNum % 25 + 1;
			randDay =RandomUtils.nextInt(25)+1;
		}
		dt.addMonths(1);
		dt.setDay(randDay);
		nextDate = CTime.formatDate(dt.getDate(), "yyyy-MM-dd");
		return nextDate;
	}

	/**
	 * 取得当天日期，字符串，格式：yyyy-MM-dd
	 * 
	 * @return
	 */
	public static String getToday() {
		DateTime dt = new DateTime();
		String today = CTime.formatDate(dt.getDate(), "yyyy-MM-dd");
		return today;
	}

	public static void main(String[] args) throws Exception {

		// 测试下月访问日期
		String strDate = MonthFeeRequestDate.getNextMonthDate();
		System.out.print(strDate);

	}

	public static String decideAccessDate(int status) {
		
		if (status == Constants.FeeStatus.IsBejin) {
			return MonthFeeRequestDate.getNextMonthDate();
		} else if (status == Constants.FeeStatus.IsInBlackList
				|| status == Constants.FeeStatus.IsInMyBlackList) {

			return "2012-99-99";

		} else if (status == Constants.FeeStatus.OverMaxDayUseChannelCnt
				|| status == Constants.FeeStatus.OverMaxDayFee
				|| status == Constants.FeeStatus.ServiceCoCloseInCurProvice
				|| status == Constants.FeeStatus.OverServiceCoUserDayFeeMax
				|| status == Constants.FeeStatus.ServiceCoDisabled
				|| status == Constants.FeeStatus.ServiceCoCloseInPacket
				|| status == Constants.FeeStatus.CloseInProvinceServiceClass
				|| status == Constants.FeeStatus.OverUserCurDayRequestCnt
				) {// 本月下次访问

			return MonthFeeRequestDate.getNextDate();

		} else if (status == Constants.FeeStatus.OverMaxMonthUseChannelCnt
				|| status == Constants.FeeStatus.OverMaxMonthUseDayCnt
				|| status == Constants.FeeStatus.OverMonthDayFee
				|| status == Constants.FeeStatus.OverServiceCoUserMonthFeeMax
				|| status == Constants.FeeStatus.FindeNoChannelRemoveScreenPrex
				|| status == Constants.FeeStatus.OverUserCurMonthReqDayCnt

		) {
			return MonthFeeRequestDate.getNextMonthDate();
		} else if (status == Constants.FeeStatus.BetweenServiceCoUserFeeInterval
				|| status == Constants.FeeStatus.FindeNoChannelByServiceClass
				|| status == Constants.FeeStatus.FindeNoChannel
				|| status == Constants.FeeStatus.FindNoChannelAfterFilterCantUse
				|| status == Constants.FeeStatus.FindNoChannelByFeeCodeAndSingleMaxCnt
				|| status == Constants.FeeStatus.FindNoChannelRemoveDayMonthMaxFee
				|| status == Constants.FeeStatus.FindeNoChannelRemoveOnlyOnce) {
			return MonthFeeRequestDate.getToday();
		} else {
			return MonthFeeRequestDate.getToday();
		}

	}

	public static boolean isNoGetPhone(int status) {
		if (status == Constants.FeeStatus.ServiceCoCloseInCurProvice
				|| status == Constants.FeeStatus.ServiceCoDisabled
				|| status == Constants.FeeStatus.ServiceCoCloseInPacket) {
			return true;
		}
		if (status == Constants.FeeStatus.IsBejin) {
			return true;
		} else if (status == Constants.FeeStatus.IsInBlackList
				|| status == Constants.FeeStatus.IsInMyBlackList) {

			return true;

		} 
		return false;
	}
}
